function loadtext(thisid,thistext) {
	var o=document.getElementById(thisid);
	o.onblur=function () {
		if(o.value=="") {
			o.value=thistext;
			$("#"+thisid).attr("class","init-text");
		}else if(o.value!==""&&o.value!==thistext) {
			$("#"+thisid).attr("class","step-text");
		}
	}
	o.onfocus=function () {
		if(o.value==thistext) {
			o.value='';
			$("#"+thisid).attr("class","step-text");
		}
	}
	o.onblur();
	
}function isInt(ints) {
	if(ints.toString ().indexOf(". ")>=0) {
		return (parseInt(ints)++);
	}else {
		return ints;
	}
}
function textCounter(field,maxlimit,talk) {
	if($("[name="+field+"]").val().length>maxlimit) {
		$("[name="+field+"]").attr("value",$("[name="+field+"]").val().substring(0,maxlimit));
		$("#content_length").html('<font style="color:red">'+tts_1.help1+'0</font>');
	}else if($("[name="+field+"]").val().length!=0) {
		var lengths=maxlimit-$("[name="+field+"]").val().length;
		$("#content_length").html('<font style="color:red">'+tts_1.help1+lengths+'</font>');
	}else {
		$("#content_length").html('');
	}
	if($("[name="+talk+"]").val()=="Kate"&&isChina($("[name="+field+"]").val())) {
		$("[name="+field+"]").attr("value","");
	}
}
	deleteCookie("fixNumber_wel");
	deleteCookie("fixNumber_offh");
	var gettext="&id=38&id=39&id=73&id=52";
	DataRequest("get_json",gettext,function(data){
		updatecfgvalue("id38",data["id38"]);
		updatecfgvalue("id38",data["id39"]);
		updatecfgvalue("id38",data["id73"]);
		updatecfgvalue("id38",data["id52"]);
 	 });
	var initstr=tts_1.help2+" "+tts_1.help2_1;
	loadtext("ivr_content",initstr);
	$("[name=help]").click(function () {
		$("#ivr_content").text(initstr);
		if($("#ivr_content").attr("class")=="step-text") {
			$("#ivr_content").attr("class","init-text");
		}else {
			$("#ivr_content").attr("class","step-text");
		}
	});
	var gettext='&id=568';
	for(var i=1;i<6;i++) {
		gettext+="&line_id="+i+"&id=67";
	}for(var i=1;i<6;i++) {
		gettext+="&line_id="+i+"&id=68";
	}
	$.ajax({
		type:"POST",url:'xml',data:'method=gw.config.get'+gettext+'&tmp='+Math.random(),dataType:"xml",error:function (xml) {
			$(xml).find('Error').each(function () {
				var errortext=$(this).attr('msg');
				alert(errortext);
			});
		},success:function (xml) {
			var rspstat=$(xml).find("rsp").attr("stat");
			if(rspstat=="ok") {
				var value568='';
				var tablehtml='';
				var welcomehtml='';
				$(xml).find("item").each(function () {
					if($(this).attr("id")=="568") {
						value568=$(this).attr("value");
					}
				});
				$(xml).find("item").each(function () {
					if($(this).attr("id")=="67") {
						var line_id1=$(this).attr("line_id");
						var thisvalue=$(this).attr("value").substr(0,20);
						if($(this).attr("value").length>20) {
							thisvalue=thisvalue+"......";
						}
						if($(this).attr("value")!=="") {
							welcomehtml+='<tr id=="welc'+line_id1+'"><td>welcome'+line_id1+'</td><td><span id="contentwel'+line_id1+'" style="display:none">'+$(this).attr("value")+'</span>'+thisvalue+'</td><td>'+value568+"3"+line_id1+'</td><td><a href="#" name="welcome" id="download_'+line_id1+'"><img src="images/listen.gif" border="0"/></a><span style="padding-left:10px;"></span><a href="#" name="delete" id="welcome_'+line_id1+'">'+sbutton.del+'</a><span style="padding-left:10px;"></span><a href="#" name="welcome_fix" id="fix_'+line_id1+'">'+tts_1.help17+'</a></td></tr>';
						}
					}else if($(this).attr("id")=="68") {
						var line_id2=$(this).attr("line_id");
						var thisvalue=$(this).attr("value").substr(0,20);
						if($(this).attr("value").length>20) {
							thisvalue=thisvalue+"......";
						}
						if($(this).attr("value")!=="") {
							tablehtml+='<tr id="offh'+line_id2+'"><td>offhour'+line_id2+'</td><td><span id="contentoff'+line_id2+'" style="display:none">'+$(this).attr("value")+'</span>'+thisvalue+'</td><td>'+value568+"4"+line_id2+'</td><td><a href="#" name="offhour" id="download_'+line_id2+'"><img src="images/listen.gif" border="0"/></a><span style="padding-left:10px;"></span><a href="#" name="delete" id="offhour_'+line_id2+'">'+sbutton.del+'</a><span style="padding-left:10px;"></span><a href="#" name="offhour_fix" id="fix_'+line_id2+'">'+tts_1.help17+'</a></td></tr>';
						}
					}
				});

				$("#ivr_welcome").html(welcomehtml);
				$("#ivr_offhour").html(tablehtml);
				
				
				$("[name=welcome_fix]").click(function () {
					var this_id=$(this).attr("id").split("_")[1];
					$("[name=id55]").attr("value",$("#contentwel"+this_id).text());
					$("[name=id55]").attr("class","step-text");
					setCookie("fixNumber_wel",this_id);
				});
				$("[name=offhour_fix]").click(function () {
					var this_id=$(this).attr("id").split("_")[1];
					$("[name=id55]").attr("value",$("#contentoff"+this_id).text());
					$("[name=id55]").attr("class","step-text");
					setCookie("fixNumber_offh",this_id);
				});
				$("[name=welcome]").click(function () {
					var thisid=$(this).attr("id").split("_")[1];
					$.ajax({
						type:"POST",url:'xml',data:'method=gw.command.set&action=download&file=welcome'+thisid+'&tmp='+Math.random(),dataType:"xml",error:function (xml) {
							$(xml).find('Error').each(function () {
								var errortext=$(this).attr('msg');
								alert(errortext);
							});
						},success:function (xml) {
							var rspstat=$(xml).find("rsp").attr("stat");
							if(rspstat=="ok") {
								var file="welcome"+thisid+".wav";
								window.top.location.href=file;
								$("#result").html("");
							}
						}
					});
				});
				$("[name=offhour]").click(function () {
					var thisid=$(this).attr("id").split("_")[1];
					$.ajax({
						type:"POST",url:'xml',data:'method=gw.command.set&action=download&file=offhour'+thisid+'&tmp='+Math.random(),dataType:"xml",error:function (xml) {
							$(xml).find('Error').each(function () {
								var errortext=$(this).attr('msg');
								alert(errortext);
							});
						},success:function (xml) {
							var rspstat=$(xml).find("rsp").attr("stat");
							if(rspstat=="ok") {
								var file="offhour"+thisid+".wav";
								window.top.location.href=file;
								$("#result").html("");
							}
						}
					});
				});
				$("[name=delete]").click(function () {
					if(confirm(tts_1.help18)) {
						var thisid=$(this).attr("id").split("_")[1];
						var flags=$(this).attr("id").split("_")[0];
						var types=0;
						if(flags=="welcome") {
							types=67;
							$("#welc"+thisid).hide();
						}else if(flags=="offhour") {
							types=68;
							$("#offh"+thisid).hide();
						}
						$.ajax({
							type:"POST",url:'xml',data:'method=gw.config.set&line_id='+thisid+'&id'+types+'=0&tmp='+Math.random(),dataType:"xml",error:function (xml) {
								$(xml).find('Error').each(function () {
									var errortext=$(this).attr('msg');
									alert(errortext);
								});
							},success:function (xml) {
								var rspstat=$(xml).find("rsp").attr("stat");
								if(rspstat=="ok"||rspstat=="reboot"||rspstat=="restart") {
									//show_message("success",tts_1.help19);
									alert(tts_1.help19);
                                    loadNewHtml("tts_main_load.htm");
								}else {
									var errorcode=$(xml).find("Error").attr("code");
									if(errorcode=="5") {
										gotologin();
									}else if(errorcode=="4") {
										//show_message("err",msg.cannotModify1);
										alert(msg.cannotModify1);
									}else {
										//show_message("err",tts_1.help7+errorcode);
										alert(tts_1.help7+errorcode);
									}
								}
							}
						});
						return true;
					}else {
						return false;
					}
				});
			}else {
				var errorcode=$(xml).find('Error').attr('code');
				if(errorcode=='5') {
					gotologin();
				}
			}
		}
	});
	$("[name=start_tts]").click(function () {
		$("#content_length").html('');
		$("[name=start_tts]").attr("disabled",true);
		$("[name=download]").attr("disabled",true);
		$("[name=work]").attr("disabled",true);
		$("[name=nowork]").attr("disabled",true);
		var settext='&id38='+$("[name=id38]").val()+"&id39="+$("[name=id39]").val()+"&id73="+$("[name=id73]").val();
		var value55=$("[name=id55]").val();
		if(value55==initstr||value55=="") {
			$("[name=start_tts]").attr("disabled",false);
			$("[name=download]").attr("disabled",false);
			$("[name=work]").attr("disabled",false);
			$("[name=nowork]").attr("disabled",false);
			alert(tts_1.help8);
            return false;
		}else {
			if(isChina(value55)) {
				setCookie("lengths",value55.length);
			}else {
				setCookie("lengths",isInt(value55.length/2));
			}
			$("#result").html(tts_1.help20+' <div class="progressbartext">0%</div>');
			if($.browser.msie){
                settext+='&id428='+encodeURIComponent(value55)+'&id55='+value55;
            }else{
                settext+='&id428='+value55+'&id55='+encodeURIComponent(value55);
            }
			$.ajax({
				type:"POST",url:'xml?method=gw.config.set'+settext+'&tmp='+Math.random(),dataType:"xml",error:function (xml) {
					$(xml).find('Error').each(function () {
						var errortext=$(this).attr('msg');
						alert(errortext);
					});
				},success:function (xml) {
					$('.progressbartext').progression({
						Current:1
					});
					var rspstat=$(xml).find("rsp").attr("stat");
					if(rspstat=="ok"||rspstat=="restart"||rspstat=="reboot") {
						var res=1;
						report=function (message) {
							$.ajax({
								type:"POST",url:'xml',data:'method=gw.config.get&id=40&tmp='+Math.random(),dataType:"xml",error:function (xml) {
									$(xml).find('Error').each(function () {
										var errortext=$(this).attr('msg');
										alert(errortext);
									});
								},success:function (xml) {
									var rspstat=$(xml).find("rsp").attr("stat");
									if(rspstat=="ok"||rspstat=="reboot"||rspstat=="restart") {
										var ttsResult=$(xml).find("item").attr("value");
										if(ttsResult=="1") {
											if(res<97) {
												res=res+3;
											}
											$('.progressbartext').progression({
												Current:res
											});
										}else if(ttsResult=="2") {
											clearInterval(timer);
											var fixNumber_wel=getCookie("fixNumber_wel");
											var fixNumber_offh=getCookie("fixNumber_offh");
											if(fixNumber_wel&&fixNumber_wel!=="") {
												$("#result").html("");
											}else if(fixNumber_offh&&fixNumber_offh!=="") {
												$("#result").html("");
											}else {
												$("#result").html("");
												//show_message("err",tts_1.help9);
												alert(tts_1.help9);
											}
											if(fixNumber_wel&&fixNumber_wel!=="") {
												var lengths=getCookie("lengths");
												$("#result").html(tts_1.help11+' <div class="progressbartext">0%</div>');
												if(lengths=="0") {
													var ss=1;
												}else {
													var ss=0;
												}var ints=isInt(100/lengths);
												progress=function (message) {
													ss=ss+ints;
													if(ss<100) {
														$('.progressbartext').progression({
															Current:ss
														});
													}
												}
												if(getCookie("type")=="MX8") {
													times=setInterval(progress,3200);
												}else {
													times=setInterval(progress,550);
												}
												$.ajax({
													type:"POST",url:'xml',data:'method=gw.config.set&line_id='+fixNumber_wel+'&id67=1&tmp='+Math.random(),dataType:"xml",error:function (xml) {
														$(xml).find('Error').each(function () {
															var errortext=$(this).attr('msg');
															alert(errortext);
														});
													},success:function (xml) {
														$('.progressbartext').progression({
															Current:100
														});
														clearInterval(times);
														var rspstat=$(xml).find("rsp").attr("stat");
														if(rspstat=="ok"||rspstat=="restart"||rspstat=="reboot") {
															$("#result").html('');
															deleteCookie("lengths");
															//show_message("err",tts_1.help10);
															alert(tts_1.help10);
															$("[name=start_tts]").show();
															$("[name=download]").show();
															$("[name=work]").show();
															$("[name=nowork]").show();
															$("[name=start_tts]").attr("disabled",false);
															$("[name=download]").attr("disabled",false);
															$("[name=work]").attr("disabled",false);
															$("[name=nowork]").attr("disabled",false);
															$("#result").html('');
                                                            loadNewHtml("tts_main_load.htm");
														}
													}
												});
											}else if(fixNumber_offh&&fixNumber_offh!=="") {
												var lengths=getCookie("lengths");
												$("#result").html(tts_1.help11+' <div class="progressbartext">0%</div>');
												if(lengths=="0") {
													var ss=1;
												}else {
													var ss=0;
												}var ints=isInt(100/lengths);
												progress=function (message) {
													ss=ss+ints;
													if(ss<100) {
														$('.progressbartext').progression({
															Current:ss
														});
													}
												}
												if(getCookie("type")=="MX8") {
													times1=setInterval(progress,3200);
												}else {
													times1=setInterval(progress,550);
												}
												$.ajax({
													type:"POST",url:'xml',data:'method=gw.config.set&line_id='+fixNumber_offh+'&id68=1&tmp='+Math.random(),dataType:"xml",error:function (xml) {
														$(xml).find('Error').each(function () {
															var errortext=$(this).attr('msg');
															alert(errortext);
														});
													},success:function (xml) {
														$('.progressbartext').progression({
															Current:100
														});
														clearInterval(times1);
														var rspstat=$(xml).find("rsp").attr("stat");
														if(rspstat=="ok"||rspstat=="restart"||rspstat=="reboot") {
															$("#result").html('');
															deleteCookie("lengths");
															//show_message("err",tts_1.help10);
															alert(tts_1.help10);
															$("[name=start_tts]").show();
															$("[name=download]").show();
															$("[name=work]").show();
															$("[name=nowork]").show();
															$("[name=start_tts]").attr("disabled",false);
															$("[name=download]").attr("disabled",false);
															$("[name=work]").attr("disabled",false);
															$("[name=nowork]").attr("disabled",false);
															$("#result").html('');
                                                            loadNewHtml("tts_main_load.htm");
														}
													}
												});
											}else {
												$("[name=start_tts]").show();
												$("[name=download]").show();
												$("[name=work]").show();
												$("[name=nowork]").show();
												$("[name=start_tts]").attr("disabled",false);
												$("[name=download]").attr("disabled",false);
												$("[name=work]").attr("disabled",false);
												$("[name=nowork]").attr("disabled",false);
											}
										}else {
											$("[name=start_tts]").attr("disabled",false);
											$("#result").html('');
											//show_message("err",tts_1.help7+ttsResult);
											alert(tts_1.help7+ttsResult);
											clearInterval(timer);
										}
									}else {
										var errorcode=$(xml).find('Error').attr('code');
										if(errorcode=='5') {
											gotologin();
										}
									}
								}
							});
						};
						timer=setInterval(report,500);
					}else {
						var errorcode=$(xml).find("Error").attr("code");
						if(errorcode=="5") {
							gotologin();
						}else if(errorcode=="4") {
							$("#result").html('');
							//show_message("err",msg.cannotModify1);
							alert(msg.cannotModify1);
						}else if(errorcode=="19") {
							//show_message("err",tts_1.help12);
							alert(tts_1.help12);
						}else {
							$("#result").html('');
							//show_message("err",cfgupload.upfail);
							alert(cfgupload.upfail);
							$("[name=start_tts]").attr("disabled",false);
						}
					}
				}
			});
		}
	});
	$("[name=download]").click(function () {
		$("[name=start_tts]").show();
		$("[name=download]").show();
		$("[name=work]").show();
		$("[name=nowork]").show();
		$.ajax({
			type:"POST",url:'xml',data:'method=gw.command.set&action=download&file=tts_file&tmp='+Math.random(),dataType:"xml",error:function (xml) {
				$(xml).find('Error').each(function () {
					var errortext=$(this).attr('msg');
					alert(errortext);
				});
			},success:function (xml) {
				var rspstat=$(xml).find("rsp").attr("stat");
				if(rspstat=="ok"||rspstat=="reboot"||rspstat=="restart") {
					var file="tts_file.wav";
					window.top.location.href=file;
					$("#result").html("");
				}
			}
		});
	});
	$("[name=work]").click(function () {
		$("[name=start_tts]").hide();
		$("[name=download]").hide();
		$("[name=work]").hide();
		$("[name=nowork]").hide();
		var gettext='';
		for(var i=1;i<6;i++) {
			gettext+="&line_id="+i+"&id=67";
		}
		$.ajax({
			type:"POST",url:'xml',data:'method=gw.config.get'+gettext+'&tmp='+Math.random(),dataType:"xml",error:function (xml) {
				$(xml).find('Error').each(function () {
					var errortext=$(this).attr('msg');
					alert(errortext);
				});
			},success:function (xml) {
				var rspstat=$(xml).find("rsp").attr("stat");
				if(rspstat=="ok") {
					var wel_num=0;
					$(xml).find("item").each(function () {
						if($(this).attr("value")=="") {
							wel_num=$(this).attr("line_id");
							return false;
						}
					});
					var lengths=getCookie("lengths");
					$("#result").html(tts_1.help11+' <div class="progressbartext">0%</div>');
					if(lengths=="0") {
						var ss=1;
					}else {
						var ss=0;
					}var ints=isInt(100/lengths);
					progress=function (message) {
						ss=ss+ints;
						if(ss<100) {
							$('.progressbartext').progression({
								Current:ss
							});
						}
					}
					if(getCookie("type")=="MX8") {
						times=setInterval(progress,3200);
					}else {
						times=setInterval(progress,550);
					}
					if(wel_num==0) {
						//show_message("err",tts_1.htlp13);
						alert(tts_1.htlp13);
						$("#result").html("");
						$("[name=start_tts]").show();
						$("[name=download]").show();
						$("[name=work]").show();
						$("[name=nowork]").show();
					}else {
						$.ajax({
							type:"POST",url:'xml',data:'method=gw.config.set&line_id='+wel_num+'&id67=1&tmp='+Math.random(),dataType:"xml",error:function (xml) {
								$(xml).find('Error').each(function () {
									var errortext=$(this).attr('msg');
									alert(errortext);
								});
							},success:function (xml) {
								$('.progressbartext').progression({
									Current:100
								});
								clearInterval(times);
								var rspstat=$(xml).find("rsp").attr("stat");
								if(rspstat=="ok"||rspstat=="restart"||rspstat=="reboot") {
									$("#result").html('');
									deleteCookie("lengths");
									//show_message("err",tts_1.help19);
									alert(tts_1.help19);
									$("[name=start_tts]").show();
									$("[name=download]").show();
									$("[name=work]").show();
									$("[name=nowork]").show();
                                    loadNewHtml("tts_main_load.htm");
								}
							}
						});
					}
				}else {
					var errorcode=$(xml).find('Error').attr('code');
					if(errorcode=='5') {
						gotologin();
					}
				}
			}
		});
	});
	$("[name=nowork]").click(function () {
		$("[name=start_tts]").hide();
		$("[name=download]").hide();
		$("[name=work]").hide();
		$("[name=nowork]").hide();
		var gettext='';
		for(var i=1;i<6;i++) {
			gettext+="&line_id="+i+"&id=68";
		}
		$.ajax({
			type:"POST",url:'xml',data:'method=gw.config.get'+gettext+'&tmp='+Math.random(),dataType:"xml",error:function (xml) {
				$(xml).find('Error').each(function () {
					var errortext=$(this).attr('msg');
					alert(errortext);
				});
			},success:function (xml) {
				var rspstat=$(xml).find("rsp").attr("stat");
				if(rspstat=="ok") {
					var offh_num=0;
					$(xml).find("item").each(function () {
						if($(this).attr("value")=="") {
							offh_num=$(this).attr("line_id");
							return false;
						}
					});
					var lengths=getCookie("lengths");
					$("#result").html(tts_1.help11+' <div class="progressbartext">0%</div>');
					if(lengths=="0") {
						var ss=1;
					}else {
						var ss=0;
					}var ints=isInt(100/lengths);
					progress=function (message) {
						ss=ss+ints;
						if(ss<100) {
							$('.progressbartext').progression({
								Current:ss
							});
						}
					}
					if(getCookie("type")=="MX8") {
						timesa=setInterval(progress,3200);
					}else {
						timesa=setInterval(progress,550);
					}
					if(offh_num==0) {
						//show_message("err",tts_1.help14);
						alert(tts_1.help14);
						$("#result").html("");
						$("[name=start_tts]").show();
						$("[name=download]").show();
						$("[name=work]").show();
						$("[name=nowork]").show();
					}else {
						$.ajax({
							type:"POST",url:'xml',data:'method=gw.config.set&line_id='+offh_num+'&id68=1&tmp='+Math.random(),dataType:"xml",error:function (xml) {
								$(xml).find('Error').each(function () {
									var errortext=$(this).attr('msg');
									alert(errortext);
								});
							},success:function (xml) {
								$('.progressbartext').progression({
									Current:100
								});
								clearInterval(timesa);
								var rspstat=$(xml).find("rsp").attr("stat");
								if(rspstat=="ok"||rspstat=="restart"||rspstat=="reboot") {
									$("#result").html('');
									//show_message("err",tts_1.help19);
									alert(tts_1.help19);
									$("[name=start_tts]").show();
									$("[name=download]").show();
									$("[name=work]").show();
									$("[name=nowork]").show();
									deleteCookie("lengths");

                                    loadNewHtml("tts_main_load.htm");
								}
							}
						});
					}
				}else {
					var errorcode=$(xml).find('Error').attr('code');
					if(errorcode=='5') {
						gotologin();
					}
				}
			}
		});
	});

	/*
	var gettext="&id=16&id=36&tmp="+Math.random();
	var dns='';	var ttsserver='';
	var url='/xml?method=gw.config.get'+gettext;
	$.get(url,function (data) {
		var stat=$(data).find('rsp').attr("stat");
		if(stat=="fail") {
			$(data).find('Error').each(function () {
				var code=$(this).attr('code');
				if(code==4) {
					//show_message("err",msg.cannotModify1);
					alert(msg.cannotModify1);
				}else if(code==5) {
					gotologin();
				}
			});
		}else {
			$(data).find("item").each(function () {
				if($(this).attr("id")=="16") {
					dns=$(this).attr("value");
				}else if($(this).attr("id")=="36") {
					ttsserver=$(this).attr("value");
				}
			});
			if(checkDomain(ttsserver)&&dns=="off") {
				//show_message("err",tts_1.help15);
				alert(tts_1.help15);
			}
			if(ttsserver=="") {
				//show_message("err",tts_1.help16);
				alert(tts_1.help16);
			}
		}
	});*/
